cask 'malwarebytes' do
  version '4.2.12.3445'
  sha256 'bf3e2393eae89252fb4b1b0e5e87b7fbe518bf263c5dbb44c3a71c7ea8833cf5'

  # data-cdn.mbamupdates.com/web was verified as official when first introduced to the cask
  url "https://data-cdn.mbamupdates.com/web/mb#{version.major}_mac/Malwarebytes-Mac-#{version}.pkg"
  appcast 'https://macupdater.net/cgi-bin/check_urls/check_url_redirect.cgi?url=https://downloads.malwarebytes.com/file/mb3-mac'
  name 'Malwarebytes for Mac'
  homepage 'https://www.malwarebytes.com/mac/'

  auto_updates true
  depends_on macos: '>= :yosemite'

  pkg "Malwarebytes-Mac-#{version}.pkg"

  uninstall delete:    '/Library/Application Support/Malwarebytes/MBAM',
            kext:      'com.malwarebytes.mbam.rtprotection',
            launchctl: [
                         'com.malwarebytes.mbam.frontend.agent',
                         'com.malwarebytes.mbam.rtprotection.daemon',
                         'com.malwarebytes.mbam.settings.daemon',
                       ],
            pkgutil:   'com.malwarebytes.mbam.*',
            quit:      'com.malwarebytes.mbam.frontend.agent',
            rmdir:     '/Library/Application Support/Malwarebytes'

  zap trash: [
               '~/Library/Application Support/com.malwarebytes.mbam.frontend.*',
               '~/Library/Saved Application State/com.malwarebytes.mbam.frontend.application.savedState',
               '~/Library/Preferences/com.malwarebytes.mbam.frontend.*',
               '~/Library/Caches/com.crashlytics.data/com.malwarebytes.mbam.frontend.*',
               '~/Library/Caches/com.malwarebytes.mbam.frontend.*',
               '~/Library/Caches/io.fabric.sdk.mac.data/com.malwarebytes.mbam.frontend.*',
             ]
end
